package pages.transitions {
	import org.splink.library.queue.IQ;
	import org.splink.library.queue.IQable;
	import org.splink.library.queue.Q;
	import org.splink.library.queue.QEvent;
	import org.splink.library.tween.QTween;
	import org.splink.library.tween.QTweenConst;

	import flash.display.DisplayObject;

	/**
	 * @author maxmc
	 */
	public class UpdateTransition {
		private var _queue : IQ;

		public function UpdateTransition() {
			_queue = new Q();
		}

		public function finalize() : void {
			_queue.finalize();
		}

		public function update(target : DisplayObject, swapFnc : Function) : void {
			_queue.finalize();
			_queue.add(createTween(target, 0, 200)).register(QEvent.COMPLETE, function(e : QEvent) : void {
				swapFnc();
			});
			_queue.add(createTween(target, 1, 300));
			_queue.start();
		}

		private function createTween(target : DisplayObject, i : int, dur : uint) : IQable {
			return new QTween(target).add(QTweenConst.ALPHA, i).duration(dur);
		}
	}
}
